﻿using System.Collections.Generic;
using System.Linq;
using Common;

namespace DataExporter
{
    public static class AppConst
    {
        private static CarType[] _nameValuePairs;
        private static Road[] _roads;
        private static ViolationCode[] _violationCodes;
        private static NameValuePair[] _lukou;
        public const string TimeFormatString = "yyyy-MM-dd HH:mm";
        public const string FilterExtension = "导出数据文件 (*.eep)|*.eep";
        public const string FileExtension = ".eep";

        public static CarType[] CarTypes
        {
            get
            {
                if (_nameValuePairs == null)
                {
                    var engineen = new FileHelpers.DelimitedFileEngine<CarType>();
                    _nameValuePairs = engineen.ReadFile("车型.txt");
                }

                return _nameValuePairs;
            }
        }

        public static Common.Road[] Roads
        {
            get
            {
                if (_roads == null)
                {
                    var engineen = new FileHelpers.DelimitedFileEngine<Common.Road>();
                    _roads = engineen.ReadFile("道路代码.txt");
                }

                return _roads;
            }
        }

        public static string FindLukouByRoad(string road)
        {
            return (from road1 in Roads where road1.Value == road select road1.LuKou).FirstOrDefault();
        }

        public static string FindRoadCodeByRoad(string road)
        {
            return (from road1 in Roads where road1.Value == road select road1.RoadCode).FirstOrDefault();
        }


        public static string FindPoliceCarCodeByProgramCode(string code)
        {
            return (from ct in CarTypes where ct.ProgramTypeCode == code select ct.PoliceTypeCode).FirstOrDefault();
        }


        public static string ConvertViolationCodeToPoliceCode(string programCode)
        {
            var code = (from c in ViolationCodes where c.FProgramCode == programCode select c.FPoliceCode).FirstOrDefault();
            return code ?? string.Empty;
        }

        public static ViolationCode[] ViolationCodes
        {
            get
            {
                if (_violationCodes == null)
                {
                    var engineen = new FileHelpers.DelimitedFileEngine<ViolationCode>();
                    _violationCodes = engineen.ReadFile("违法代码.txt");
                }

                return _violationCodes;
            }
        }

        public static NameValuePair[] Lukous
        {
            get
            {
                if (_lukou == null)
                {
                    _lukou = new FileHelpers.DelimitedFileEngine<NameValuePair>().ReadFile("路口.txt");
                }

                return _lukou;
            }
        }
    }
}
